/**
 * Class: Note
 *
 * Purpose: 
 *
 * Created: Jan 30, 2010 @ 8:58:10 AM
 * @author Ken Scott
 */
package org.openfantasia.musica.events;

import org.openfantasia.musica.Musica;
import org.openfantasia.musica.instruments.Instrument;

public class Note extends Event {

	protected Instrument instrument;

	protected double frequency;

	protected double volume;


	protected Note() {
	}


	public Note(Musica mc) {
		super(mc);
	}


	public Note(Musica mc, Instrument instrument, double frequency, double volume, int durationID) {
		super(mc);
		setName("Note: " + instrument.getName() + ": " + mc.getFrequencyToneName(frequency) + " " + Musica.getNoteDurationName(durationID) + " @ vol " + volume);
		this.instrument = instrument;
		this.frequency = frequency;
		this.volume = volume;
		this.duration = durationID;
	}


	public Note(Musica mc, Instrument instrument, String noteName, double volume, int durationID) {
		super(mc);
		setName("Note: " + instrument.getName() + " - " + noteName + " - " + Musica.getNoteDurationName(durationID) + " @ vol " + volume);
		this.instrument = instrument;
		this.frequency = mc.getToneFrequency(noteName);
		this.volume = volume;
		this.duration = durationID;
	}


	public Note(Note that) {
		copy(that);
	}


	public Note copy() {
		return new Note(this);
	}


	public void copy(Note that) {
		super.copy(that);
		this.instrument = that.instrument;
		this.frequency = that.frequency;
		this.volume = that.volume;
		this.duration = that.duration;
	}


	public void action() {
		instrument.play(this);
	}


	public void play() {
		instrument.play(this);
	}


	public Instrument getInstrument() {
		return instrument;
	}


	public double getFrequency() {
		return frequency;
	}


	public double getVolume() {
		return volume;
	}


	public void transpose(Event event, int amount) {
		int idx = musica.getToneFrequencyIndex(((Note) event).frequency);
		((Note) event).frequency = musica.getToneFrequency(idx + amount);
	}
}
